package com.mars.module.app.controller;


import com.mars.common.enums.BusinessType;
import com.mars.common.response.PageInfo;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import com.mars.common.util.TokenUtils;
import com.mars.framework.annotation.Log;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.ApUser;
import com.mars.module.admin.request.ApUserRequest;
import com.mars.module.admin.response.UserInfoResponse;
import com.mars.module.admin.service.IApUserService;
import com.mars.module.app.request.AppLoginRequest;
import com.mars.module.app.request.AppRegisterRequest;
import com.mars.module.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 用户控制层
 *
 * @author mars
 * @date 2024-02-24
 */
@Slf4j
@RestController
@Api(value = "用户接口管理", tags = "用户接口管理")
@RequestMapping("/app/apUser")
public class AppUserController extends BaseController {


    @Resource
    private IApUserService iApUserService;

    public AppUserController(TokenUtils tokenUtils) {
        super(tokenUtils);
    }

    /**
     * 新增用户
     */
    @ApiOperation(value = "app/apUser/getInfo用户登录")
    @PostMapping("/login")
    public R<String> login(@RequestBody AppLoginRequest apUserRequest) {
        return R.success(iApUserService.login(apUserRequest));
    }

    /**
     * 用户注册
     */
    @ApiOperation(value = "用户注册")
    @PostMapping("/register")
    public R<Void> register(@RequestBody AppRegisterRequest apUserRequest) {
        iApUserService.register(apUserRequest);
        return R.success();
    }

    /**
     * 修改用户信息
     */
    @ApiOperation(value = "修改用户信息")
    @PostMapping("/update")
    public R<Void> update(@RequestBody ApUserRequest apUserRequest) {
        iApUserService.update(apUserRequest);
        return R.success();
    }

    /**
     * 获取用户信息
     *
     * @return R
     */
    @ApiOperation(value = "获取用户信息")
    @GetMapping("/getInfo")
    public R<UserInfoResponse> getInfo() {
        return R.success(iApUserService.getUserInfo(getUserId()));
    }


}
